package day05;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/14
 *
 * 练习4：已知图片名称，截取出图片的格式
 */
public class TestString04 {
    public static void main(String[] args) {
        String name1="photo.jpg";
        String name2="photo.gif";
        String name3="photo.png";
        String name4="photo";
        System.out.println(cut(name1));
        System.out.println(cut(name2));
        System.out.println(cut(name3));
        System.out.println(cut(name4));
    }
    public static String cut(String str){
        if(str==null||str.length()==0){
            return " ";
        }
        int lastIndex = str.lastIndexOf('.');
        if(lastIndex==-1 || lastIndex==str.length()-1){
            return " ";
        }
        return str.substring(lastIndex+1);
    }
}
